package myweb.myTcp;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class TcpClient {

    public static void main(String[] args) {
        try {
            Socket s = new Socket(InetAddress.getByName("127.0.0.1"), 8001);
            InputStream inputStream = s.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            OutputStream outputStream = s.getOutputStream();
            DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
            BufferedReader brKey = new BufferedReader(new InputStreamReader(System.in));
            while (true){
                String strWord = brKey.readLine();
                if (strWord.equalsIgnoreCase("quit")){
                    break;
                }else{
                    System.out.println("I want to send :"+strWord);
                    /**  System.getProperty("line.separator")
                     * 获取操作系统对应的换行符
                     * java中的转义符"\r\n":
                     * windows下的文本文件换行符:\r\n
                     * linux/unix下的文本文件换行符:\r
                     * Mac下的文本文件换行符:\n
                     *
                     * */
                    dataOutputStream.writeBytes(strWord+System.getProperty("line.separator"));
                    System.out.println("Server said:"+bufferedReader.readLine());
                }
            }
            dataOutputStream.close();
            outputStream.close();
            inputStream.close();
            s.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
